package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ResponseReport;
import com.ruoyi.system.service.IResponseReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 一键上报Controller
 * 
 * @author ruoyi
 * @date 2021-07-01
 */
@RestController
@RequestMapping("/system/responseReport")
public class ResponseReportController extends BaseController
{
    @Autowired
    private IResponseReportService responseReportService;

    /**
     * 查询一键上报列表
     */
//    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResponseReport responseReport)
    {
        startPage();
        List<ResponseReport> list = responseReportService.selectResponseReportList(responseReport);
        return getDataTable(list);
    }

    /**
     * 导出一键上报列表
     */
//    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "一键上报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ResponseReport responseReport)
    {
        List<ResponseReport> list = responseReportService.selectResponseReportList(responseReport);
        ExcelUtil<ResponseReport> util = new ExcelUtil<ResponseReport>(ResponseReport.class);
        return util.exportExcel(list, "report");
    }

    /**
     * 获取一键上报详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{rId}")
    public AjaxResult getInfo(@PathVariable("rId") Long rId)
    {
        return AjaxResult.success(responseReportService.selectResponseReportById(rId));
    }

    /**
     * 新增一键上报
     */
//    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "一键上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResponseReport responseReport)
    {
        return toAjax(responseReportService.insertResponseReport(responseReport));
    }

    /**
     * 修改一键上报
     */
//    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "一键上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResponseReport responseReport)
    {
        return toAjax(responseReportService.updateResponseReport(responseReport));
    }

    /**
     * 删除一键上报
     */
//    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "一键上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rIds}")
    public AjaxResult remove(@PathVariable Long[] rIds)
    {
        return toAjax(responseReportService.deleteResponseReportByIds(rIds));
    }
}
